# coding: utf-8

from typing import Sequence
from vec2 import vec2
from graph import GraphAttr, NodeAttr, Hierarchy
from .Positioning import Positioning


# demo: Positioning使用方法
class DemoPositioning(Positioning):
    nodes: Sequence[NodeAttr]

    def __init__(self, attr: GraphAttr, h: Hierarchy):
        self.nodes = []
        self.attr = attr
        h = h

    def run(self, h: Hierarchy, origin: vec2) -> vec2:
        y: float = origin.y + self.attr.layer_dist
        width: float = 0
        for layer in h.layers:
            x: float = origin.x
            for u in layer:
                x += self.attr.node_dist + self.attr.node_size
                # TODO class Bounding_Box 里的size

                self.nodes[u].pos = vec2(x, y)
                self.nodes[u].size = self.attr.node_size
                x += self.attr.node_size

            if (x - origin.x) > width:
                width = x

            y += self.attr.layer_dist

        return vec2(width, y - origin.y)
